package com.wyp.demo.pattern.proxy.cglb;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * cglib  aspect创建
 *
 * @author: Oliver
 * @time: 2020/12/20/15:03
 */
public class CommonMethodInteceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        before();
        Object result = methodProxy.invokeSuper(proxy, args);
        after();
        return result;
    }

    private void before() {
        System.out.println("调用开始之前,从卡里取钱");
    }

    private void after() {
        System.out.println("调用结束之后,扣钱成功");
    }
}
